<?php
namespace app\admin\controller\user;

use app\admin\model\user\UserCar as UserCarModel;
use app\admin\BaseController;
use think\App;
use think\facade\View;
use think\facade\Request;

class UserCar extends BaseController
{
    /**
     * 列表页面
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        return View::fetch('user/userCar/index');
    }

    /**
     * 获取列表
     * @return $this
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function list(){
        [$page,$limit] = $this->getPage();
        $getData = Request::post();
        if(isset($getData['is_authentication']) && $getData['is_authentication'] == 2){
            $getData['is_authentication'] = 0;
        }
        $userCarModel = new UserCarModel();
        $backData = $userCarModel->getList($getData,$page,$limit);
        $backData['code'] = 0;
        $backData['msg'] = '获取成功';
        return json()->data($backData);
    }

    /**
     * 编辑表单
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function editForm(){
        $id = Request::get('id');
        $userCarModel = new UserCarModel();
        $info = $userCarModel->getInfoById($id);
        $infoStatus = 0;
        if($info) $infoStatus = 1;
        View::assign('info', $info);
        View::assign('infoStatus', $infoStatus);
        return View::fetch('user/userCar/edit');
    }

    /**
     * 修改内容
     * @return $this
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function updateData(){
        $getData = Request::post();
        if(!$getData['id']) return $this->fail('请选择用户');
        $userCarModel = new UserCarModel();
        $result = $userCarModel->editData($getData['id'],$getData);
        if($result) return $this->success('修改成功');
        return $this->fail('未作任何修改');
    }



}


